package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysBrick;
import com.ruoyi.system.service.ISysBrickService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 瓷砖Controller
 *
 * @author Yanghc
 * @date 2024-08-16
 */
@Controller
@RequestMapping("/system/brick")
public class SysBrickController extends BaseController
{
    private String prefix = "system/brick";

    @Autowired
    private ISysBrickService sysBrickService;

    @RequiresPermissions("system:brick:view")
    @GetMapping()
    public String brick()
    {
        return prefix + "/brick";
    }

    /**
     * 查询瓷砖列表
     */
    @RequiresPermissions("system:brick:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysBrick sysBrick)
    {
        startPage();
        List<SysBrick> list = sysBrickService.selectSysBrickList(sysBrick);
        return getDataTable(list);
    }

    /**
     * 导出瓷砖列表
     */
    @RequiresPermissions("system:brick:export")
    @Log(title = "瓷砖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysBrick sysBrick)
    {
        List<SysBrick> list = sysBrickService.selectSysBrickList(sysBrick);
        ExcelUtil<SysBrick> util = new ExcelUtil<SysBrick>(SysBrick.class);
        return util.exportExcel(list, "瓷砖数据");
    }

    /**
     * 新增瓷砖
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存瓷砖
     */
    @RequiresPermissions("system:brick:add")
    @Log(title = "瓷砖", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysBrick sysBrick)
    {
        return toAjax(sysBrickService.insertSysBrick(sysBrick));
    }

    /**
     * 修改瓷砖
     */
    @RequiresPermissions("system:brick:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysBrick sysBrick = sysBrickService.selectSysBrickById(id);
        mmap.put("sysBrick", sysBrick);
        return prefix + "/edit";
    }

    /**
     * 修改保存瓷砖
     */
    @RequiresPermissions("system:brick:edit")
    @Log(title = "瓷砖", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysBrick sysBrick)
    {
        return toAjax(sysBrickService.updateSysBrick(sysBrick));
    }

    /**
     * 删除瓷砖
     */
    @RequiresPermissions("system:brick:remove")
    @Log(title = "瓷砖", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysBrickService.deleteSysBrickByIds(ids));
    }
}
